<template>
    <div style=" margin-top: -500px;margin-left: 400px;margin-bottom:90px">
        <h2>用户:{{ username }} &emsp;昵称:{{ nickname }} &emsp;在职位名称:{{ job_title }}&emsp;下的简历</h2>
        <div class="seekerForm">
            <el-descriptions title="" direction="vertical" :column="3" border style="margin-bottom:50px">
                <el-descriptions-item label="姓名">
                    <el-input v-model="seeker.full_name" disabled></el-input>
                </el-descriptions-item>
                <el-descriptions-item label="性别">
                    <el-input v-model="seeker.gender" disabled></el-input>
                </el-descriptions-item>
                <el-descriptions-item label="年龄">
                    <el-input v-model="seeker.age" disabled></el-input>
                </el-descriptions-item>
                <el-descriptions-item label="学历">
                    <el-input v-model="seeker.education" disabled></el-input>
                </el-descriptions-item>
                <el-descriptions-item label="毕业院校">
                    <el-input v-model="seeker.university_one_is_graduated_from" disabled></el-input>
                </el-descriptions-item>
                <el-descriptions-item label="毕业年度">
                    <el-input v-model="seeker.graduation_year" disabled></el-input>
                </el-descriptions-item>
            </el-descriptions>
        </div>
        <div class="resumeForm">
            <el-descriptions title="" direction="vertical" :column="3" border style="margin-bottom:50px">
                <el-descriptions-item label="简历名称">
                    <el-input v-model="resume.resume_name" disabled></el-input>
                </el-descriptions-item>
                <el-descriptions-item label="投递时间">
                    <el-tag size="medium" style="margin-top:5px">{{ format(deliverTime).format }}</el-tag>
                </el-descriptions-item>
                <el-descriptions-item label="个人优势">
                    <el-input v-model="resume.personal_advantages" disabled></el-input>
                </el-descriptions-item>
                <el-descriptions-item label="工作经历">
                    <el-input v-model="resume.work_experience" disabled></el-input>
                </el-descriptions-item>
                <el-descriptions-item label="项目经历">
                    <el-input v-model="resume.project_experience" disabled></el-input>
                </el-descriptions-item>
                <el-descriptions-item label="简历附件">
                    <el-button type="success" v-if="resume.resume_attachment" @click="downloadResume">下载简历附件</el-button>
                    <span v-else style="color:red">暂无</span>
                </el-descriptions-item>
                <el-descriptions-item label="您的回复">
                    <el-input v-if="isReplyContentNull" v-model="oldReplyContent" disabled></el-input>
                    <span v-else style="color:red">暂无</span>
                </el-descriptions-item>
                <el-descriptions-item label="操作">
                    <el-button type="success" @click="toReply">回复</el-button>
                </el-descriptions-item>
            </el-descriptions>
        </div>
        <div v-show="isReply">
            <el-input type="textarea" v-model="newReplyContent"></el-input>
            <el-button type="primary" style="margin-top:10px" @click="sendReply">提交</el-button>
        </div>
    </div>
</template>
<script>
import axios from 'axios';
import dateTime from '@/utils/date_time';
export default {
    data() {
        return {
            resume: {},
            seeker: {},
            deliver_resume_id: 0,
            username: '',
            nickname: '',
            job_title: '',
            isReply: false,
            newReplyContent: '',
            oldReplyContent: '',
            deliverTime: '',
            isReplyContentNull: true
        }
    },
    methods: {
        sendReply() {
            let that = this;
            axios({
                method: 'post',
                url: 'http://127.0.0.1:5000/api/deliver_resume/set?deliver_resume_id=' + that.deliver_resume_id,
                data: {
                    enterprise_reply: that.newReplyContent,
                },
                headers: {
                    'X-Auth-Token': window.localStorage.getItem("token")
                },
            })
                .then(function (response) {
                    if (response.data.result) {
                        that.$message.success("回复成功");
                        window.location.reload();
                    } else {
                        that.$message.error("回复失败");
                        window.location.reload();
                    }
                })
                .catch(function (error) {
                    console.log(error);
                })
                .then(function () {
                    // 总是会执行
                })
        },
        downloadResume() {
            let resumeFileName = this.resume.resume_attachment.split('/');
            window.open('http://127.0.0.1:5000/api/upload/resume/' + resumeFileName[2]);
        },
        getResume(id) {
            let that = this;
            axios({
                method: 'get',
                url: 'http://127.0.0.1:5000/api/resume_management/get_obj',
                params: {
                    resume_management_id: id,
                },
                headers: {
                    'X-Auth-Token': window.localStorage.getItem("token")
                },
            })
                .then(function (response) {
                    if (response.data.result.obj) {
                        that.resume = response.data.result.obj;
                    }
                })
                .catch(function (error) {
                    console.log(error);
                })
                .then(function () {
                    // 总是会执行
                })
        },
        getUser(id) {
            let that = this;
            axios({
                method: 'get',
                url: 'http://127.0.0.1:5000/api/user/get_obj',
                params: {
                    user_id: id,
                },
                headers: {
                    'X-Auth-Token': window.localStorage.getItem("token")
                },
            })
                .then(function (response) {
                    if (response.data.result.obj) {
                        that.username = response.data.result.obj.username;
                        that.nickname = response.data.result.obj.nickname;
                    }
                })
                .catch(function (error) {
                    console.log(error);
                })
                .then(function () {
                    // 总是会执行
                })
        },
        getSeeker(id) {
            let that = this;
            axios({
                method: 'get',
                url: 'http://127.0.0.1:5000/api/job_seekers/get_obj',
                params: {
                    job_seekers_id: id,
                },
                headers: {
                    'X-Auth-Token': window.localStorage.getItem("token")
                },
            })
                .then(function (response) {
                    if (response.data.result.obj) {
                        that.seeker = response.data.result.obj;
                        that.getUser(response.data.result.obj.user_id);
                    }
                })
                .catch(function (error) {
                    console.log(error);
                })
                .then(function () {
                    // 总是会执行
                })
        },
        toReply() {
            this.isReply = true;
        },
        format(create_time) {
            return dateTime.dateTime(create_time)
        },
    },
    created: function () {
        let that = this;
        that.deliver_resume_id = window.localStorage.getItem("deliver_resume_id");
        if (that.$route.params.deliver_resume_id) {
            that.deliver_resume_id = that.$route.params.deliver_resume_id;
        }
        axios({
            method: 'get',
            url: 'http://127.0.0.1:5000/api/deliver_resume/get_obj',
            params: {
                deliver_resume_id: that.deliver_resume_id,
            },
            headers: {
                'X-Auth-Token': window.localStorage.getItem("token")
            },
        })
            .then(function (response) {
                console.log(response.data);
                if (response.data.result.obj) {
                    window.localStorage.setItem("deliver_resume_id", response.data.result.obj.deliver_resume_id);
                    that.job_title = response.data.result.obj.job_title;
                    that.getResume(response.data.result.obj.resume_management_id);
                    that.getSeeker(response.data.result.obj.job_seekers);
                    that.deliverTime = response.data.result.obj.create_time;
                    that.oldReplyContent = response.data.result.obj.enterprise_reply;
                }
            })
            .catch(function (error) {
                console.log(error);
            })
            .then(function () {
                // 总是会执行
            })
    },
}
</script>
<style lang="less" scoped>
.resumeForm {
    margin-top: -50px;
}
</style>